<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo/css/main.css">


<link rel="stylesheet" href="/hexo/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"youchen12138.gitee.io","root":"/hexo/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="滑动视图（PageView）123456789101112131415161718192021222324252627282930313233343536373839404142class ViewDemo extends StatelessWidget &amp;#123;  @override  Widget build(BuildContext context) &amp;#123;    return P">
<meta property="og:type" content="article">
<meta property="og:title" content="Flutter-视图">
<meta property="og:url" content="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E8%A7%86%E5%9B%BE/index.html">
<meta property="og:site_name" content="幽辰的博客">
<meta property="og:description" content="滑动视图（PageView）123456789101112131415161718192021222324252627282930313233343536373839404142class ViewDemo extends StatelessWidget &amp;#123;  @override  Widget build(BuildContext context) &amp;#123;    return P">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-a11e48e35ea64c30.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-7d1b2d634e9ece78.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-997d57361785b261.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-917ad5ed46c0a479.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-9e7201591632bc10.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-42291b06113f5c4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/16731485-b6dd63814e7e7c71.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="article:published_time" content="2020-08-26T08:42:22.000Z">
<meta property="article:modified_time" content="2020-08-26T08:42:46.503Z">
<meta property="article:author" content="幽辰">
<meta property="article:tag" content="Flutter">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/16731485-a11e48e35ea64c30.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">

<link rel="canonical" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E8%A7%86%E5%9B%BE/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>Flutter-视图 | 幽辰的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">幽辰的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/hexo/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/hexo/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/hexo/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/hexo/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives<span class="badge">127</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-%E8%A7%86%E5%9B%BE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Flutter-视图
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:42:22 / Modified: 16:42:46" itemprop="dateCreated datePublished" datetime="2020-08-26T16:42:22+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="滑动视图（PageView）"><a href="#滑动视图（PageView）" class="headerlink" title="滑动视图（PageView）"></a>滑动视图（PageView）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">class ViewDemo extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return PageView(</span><br><span class="line">      children: &lt;Widget&gt;[</span><br><span class="line">        Container(</span><br><span class="line">          color: Colors.brown[900],</span><br><span class="line">          alignment: Alignment.center,</span><br><span class="line">          child: Text(</span><br><span class="line">            &#39;ONE&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">              fontSize: 32,</span><br><span class="line">              color: Colors.white</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">        Container(</span><br><span class="line">          color: Colors.grey[900],</span><br><span class="line">          alignment: Alignment.center,</span><br><span class="line">          child: Text(</span><br><span class="line">            &#39;TWO&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">                fontSize: 32,</span><br><span class="line">                color: Colors.white</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">        Container(</span><br><span class="line">          color: Colors.blueGrey[900],</span><br><span class="line">          alignment: Alignment.center,</span><br><span class="line">          child: Text(</span><br><span class="line">            &#39;THREE&#39;,</span><br><span class="line">            style: TextStyle(</span><br><span class="line">                fontSize: 32,</span><br><span class="line">                color: Colors.white</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ],</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-a11e48e35ea64c30.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="主要属性"><a href="#主要属性" class="headerlink" title="主要属性"></a>主要属性</h3><h4 id="不知道起什么中文名的属性（pageSnapping）"><a href="#不知道起什么中文名的属性（pageSnapping）" class="headerlink" title="不知道起什么中文名的属性（pageSnapping）"></a>不知道起什么中文名的属性（pageSnapping）</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 将此属性设置为false，不管划到什么程度，视图都会停下来，而不是强制显示一个完整的视图</span><br><span class="line">pageSnapping: false, </span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-7d1b2d634e9ece78.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h4 id="反转（reserve）"><a href="#反转（reserve）" class="headerlink" title="反转（reserve）"></a>反转（reserve）</h4><p>视图会发生反转，第一个会变成最后一个</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reverse: true, &#x2F;&#x2F; 反转</span><br></pre></td></tr></table></figure>
<h4 id="滚动方向（scrollDirection）"><a href="#滚动方向（scrollDirection）" class="headerlink" title="滚动方向（scrollDirection）"></a>滚动方向（scrollDirection）</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">scrollDirection: Axis.vertical, &#x2F;&#x2F; 滚动方向。默认为horizontal</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-997d57361785b261.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="滚动方向"></p>
<h4 id="onPageChanged"><a href="#onPageChanged" class="headerlink" title="onPageChanged"></a>onPageChanged</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">onPageChanged: (currentPage) &#x3D;&gt; debugPrint(&#39;Page: $currentPage&#39;), &#x2F;&#x2F; 当切换到其他视图时会触发这个函数</span><br></pre></td></tr></table></figure>
<h4 id="controller"><a href="#controller" class="headerlink" title="controller"></a>controller</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">controller: PageController( &#x2F;&#x2F; 设置</span><br><span class="line">  initialPage: 1, &#x2F;&#x2F; 初始显示的页面</span><br><span class="line">  keepPage: false, &#x2F;&#x2F; 是否保存当前Page的状态，initialPage将会被忽略。如果为false，下次总是从initial开始</span><br><span class="line">  viewportFraction: 1 &#x2F;&#x2F; 占屏幕多少</span><br><span class="line">),</span><br></pre></td></tr></table></figure>
<h3 id="builder"><a href="#builder" class="headerlink" title="builder"></a>builder</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">class PageViewBuilderDemo extends StatelessWidget &#123;</span><br><span class="line">  Widget _pageItemBuilder(BuildContext context, int index)&#123;</span><br><span class="line">    return Stack(</span><br><span class="line">      children: &lt;Widget&gt;[</span><br><span class="line">        SizedBox.expand(</span><br><span class="line">          child: Image.network(</span><br><span class="line">            posts[index].imageUrl,</span><br><span class="line">            fit: BoxFit.cover,</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">        Positioned(</span><br><span class="line">          bottom: 8,</span><br><span class="line">          left: 8,</span><br><span class="line">          child: Column(</span><br><span class="line">            crossAxisAlignment: CrossAxisAlignment.start,</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              Text(</span><br><span class="line">                posts[index].title,</span><br><span class="line">                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),</span><br><span class="line">              ),</span><br><span class="line">              Text(</span><br><span class="line">                posts[index].author,</span><br><span class="line">              )</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        )</span><br><span class="line">      ],</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return PageView.builder(</span><br><span class="line">      itemCount: posts.length, &#x2F;&#x2F; 数量</span><br><span class="line">      itemBuilder: _pageItemBuilder, &#x2F;&#x2F; 构造方法</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-917ad5ed46c0a479.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h2 id="网格视图（GridView）"><a href="#网格视图（GridView）" class="headerlink" title="网格视图（GridView）"></a>网格视图（GridView）</h2><h3 id="count"><a href="#count" class="headerlink" title="count"></a>count</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">class GridViewCountDemo extends StatelessWidget &#123;</span><br><span class="line">  List&lt;Widget&gt; _buildTiles(int length)&#123;</span><br><span class="line">    return List.generate(length, (int index)&#123;</span><br><span class="line">      return Container(</span><br><span class="line">        color: Colors.grey[300],</span><br><span class="line">        alignment: Alignment.center,</span><br><span class="line">        child: Text(</span><br><span class="line">          &#39;Item $index&#39;,</span><br><span class="line">          style: TextStyle(fontSize: 18, color: Colors.grey),</span><br><span class="line">        ),</span><br><span class="line">      );</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return GridView.count(</span><br><span class="line">      crossAxisCount: 3, &#x2F;&#x2F; 交叉轴的数量</span><br><span class="line">      crossAxisSpacing: 16, &#x2F;&#x2F; 交叉轴之间的间距</span><br><span class="line">      mainAxisSpacing: 16, &#x2F;&#x2F; 主轴之间的间距</span><br><span class="line">      scrollDirection: Axis.horizontal,</span><br><span class="line">      children: _buildTiles(50),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-9e7201591632bc10.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="extent"><a href="#extent" class="headerlink" title="extent"></a>extent</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">class GridViewExtentDemo extends StatelessWidget &#123;</span><br><span class="line">  List&lt;Widget&gt; _buildTiles(int length)&#123;</span><br><span class="line">    return List.generate(length, (int index)&#123;</span><br><span class="line">      return Container(</span><br><span class="line">        color: Colors.grey[300],</span><br><span class="line">        alignment: Alignment.center,</span><br><span class="line">        child: Text(</span><br><span class="line">          &#39;Item $index&#39;,</span><br><span class="line">          style: TextStyle(fontSize: 18, color: Colors.grey),</span><br><span class="line">        ),</span><br><span class="line">      );</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return GridView.extent(</span><br><span class="line">      maxCrossAxisExtent: 150, &#x2F;&#x2F; 子项在主轴最大的宽度&#x2F;高度</span><br><span class="line">      crossAxisSpacing: 16,</span><br><span class="line">      mainAxisSpacing: 16,</span><br><span class="line">      scrollDirection: Axis.horizontal,</span><br><span class="line">      children: _buildTiles(50),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-42291b06113f5c4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<h3 id="build"><a href="#build" class="headerlink" title="build"></a>build</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">class GridViewBuilderDemo extends StatelessWidget &#123;</span><br><span class="line">  Widget _gridItemBuilder(BuildContext context, int index)&#123;</span><br><span class="line">    return Container(</span><br><span class="line">      child: Image.network(</span><br><span class="line">        posts[index].imageUrl,</span><br><span class="line">        fit: BoxFit.cover,</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return GridView.builder(</span><br><span class="line">      padding: EdgeInsets.all(8),</span><br><span class="line">      itemCount: posts.length,</span><br><span class="line">      itemBuilder: _gridItemBuilder,</span><br><span class="line">      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( &#x2F;&#x2F; 控制显示</span><br><span class="line">        crossAxisCount: 3, &#x2F;&#x2F; 交叉轴数量为3</span><br><span class="line">        crossAxisSpacing: 16, &#x2F;&#x2F; 交叉轴中各项间距为8</span><br><span class="line">        mainAxisSpacing: 16 &#x2F;&#x2F; 主轴间距为8</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-b6dd63814e7e7c71.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/hexo/tags/Flutter/" rel="tag"># Flutter</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/hexo/2020/08/26/Flutter-AspectRadio/" rel="prev" title="Flutter-AspectRadio">
      <i class="fa fa-chevron-left"></i> Flutter-AspectRadio
    </a></div>
      <div class="post-nav-item">
    <a href="/hexo/2020/08/26/Flutter-Sliver/" rel="next" title="Flutter-Sliver">
      Flutter-Sliver <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%BB%91%E5%8A%A8%E8%A7%86%E5%9B%BE%EF%BC%88PageView%EF%BC%89"><span class="nav-number">1.</span> <span class="nav-text">滑动视图（PageView）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%BB%E8%A6%81%E5%B1%9E%E6%80%A7"><span class="nav-number">1.1.</span> <span class="nav-text">主要属性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%B8%8D%E7%9F%A5%E9%81%93%E8%B5%B7%E4%BB%80%E4%B9%88%E4%B8%AD%E6%96%87%E5%90%8D%E7%9A%84%E5%B1%9E%E6%80%A7%EF%BC%88pageSnapping%EF%BC%89"><span class="nav-number">1.1.1.</span> <span class="nav-text">不知道起什么中文名的属性（pageSnapping）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%8D%E8%BD%AC%EF%BC%88reserve%EF%BC%89"><span class="nav-number">1.1.2.</span> <span class="nav-text">反转（reserve）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%BB%9A%E5%8A%A8%E6%96%B9%E5%90%91%EF%BC%88scrollDirection%EF%BC%89"><span class="nav-number">1.1.3.</span> <span class="nav-text">滚动方向（scrollDirection）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#onPageChanged"><span class="nav-number">1.1.4.</span> <span class="nav-text">onPageChanged</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#controller"><span class="nav-number">1.1.5.</span> <span class="nav-text">controller</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#builder"><span class="nav-number">1.2.</span> <span class="nav-text">builder</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BD%91%E6%A0%BC%E8%A7%86%E5%9B%BE%EF%BC%88GridView%EF%BC%89"><span class="nav-number">2.</span> <span class="nav-text">网格视图（GridView）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#count"><span class="nav-number">2.1.</span> <span class="nav-text">count</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#extent"><span class="nav-number">2.2.</span> <span class="nav-text">extent</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#build"><span class="nav-number">2.3.</span> <span class="nav-text">build</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="幽辰"
      src="/hexo/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">幽辰</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo/archives/">
        
          <span class="site-state-item-count">127</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo/tags/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">幽辰</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/hexo/lib/anime.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.ui.min.js"></script>

<script src="/hexo/js/utils.js"></script>

<script src="/hexo/js/motion.js"></script>


<script src="/hexo/js/schemes/pisces.js"></script>


<script src="/hexo/js/next-boot.js"></script>




  















  

  

</body>
</html>
